// 页面加载
$(function(){
  // 设置页面高度
  setBodyHeight();

  // 设置菜单悬停点击样式
  setBgStyle();

  showList();
});

//扩展jquery获取url参数方法
(function ($) {
  $.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r   = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
  }
})(jQuery);

// 调整窗口尺寸
$(window).resize(function () {
  setBodyHeight();
});

// 添加tab标签
function addTab(obj){
  // alert($(obj).attr("appurl"));
  $("#header_menu>ul>li:#more_tab").before("<li class=\"common\" id=\"shoujian1\">人员管理<a href=\"javascript:void(0)\" class=\"tab_close\" onclick=\"closeTab(this)\"></a></li>");
  $("#tablist>ul>li:last").after("<li>人员管理<a href=\"javascript:void(0)\" class=\"tab_close\" onclick=\"closeTab(this)\"></a></li>")
  setBgStyle();
}

// 关闭标签
function closeTab (obj) {
  if($(obj).parent().attr("class")=="select"){
    $(obj).parent().prev().attr("class","select");
  }
  $(obj).parent().remove();

}

function showList(){
  $("#more_tab").click(function(){
	if($("#tablist").attr("class")=="tablist_show"){
		$("#tablist").attr("class","tablist_hide");
	}else{
		$("#tablist").attr("class","tablist_show");
	}
  });
  $("body").click(function(event){
    var $target = $(event.target);
    // alert($(event.target));
    // alert($(this).html());
   // $("#tablist").hide();
 });
}

// 设置菜单悬停点击样式
function setBgStyle () {
  // 设置标签选中
  $("#header_menu>ul>li").click(function(event) {
    if($(this).attr("class")!="more"){
      $(this).parent().children().each(function(){
        if($(this).attr("class")!="more"){
          $(this).attr("class","common");
        }
      });
      $(this).attr("class","select");
    }
  });
}

// 设置页面高度
function setBodyHeight() {
  var pagesize=getPageSize();
  $("#body").css("height", pagesize[3] - 88);
  // $("#body>.tab-pane").each(function(){
  //   // alert($(this).html());
  //   $(this).css("height", document.documentElement.clientHeight - 88);
  //   $(this).find("iframe").css("height", document.documentElement.clientHeight - 88);
  // });
}

function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else {
        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
        }
    }
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
}


